//
//  ZYCHomeRootParentHeaderView.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/12.
//

#import "ZYCHomeRootParentHeaderView.h"
#import <SDCycleScrollView.h>
#import "BTRootImageTItleVIew.h"
#import "ZYCWheelBannerModel.h"

@interface ZYCHomeRootParentHeaderView ()<SDCycleScrollViewDelegate,BTRootImageTitleViewDelegate>

@property (nonatomic, strong) UIImageView *topImageView;
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView1;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView2;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView3;
@property (nonatomic, strong) BTRootImageTItleVIew *imageTitleView4;


@end
@implementation ZYCHomeRootParentHeaderView
//http://111.22.13.139:9900/zd-system-service/data/hdfs/base/2021/8/21/25c92dfff56b44b992a9061d5c13b73b_1629530379518.JPG
- (void)setWheelBannerList:(NSArray *)wheelBannerList{
    _wheelBannerList = wheelBannerList;
    NSMutableArray *tempArr = [NSMutableArray arrayWithCapacity:0];
    for (ZYCWheelBannerModel *model in wheelBannerList) {
        NSString *imgUrl = [[NSString stringWithFormat:@"%@/zd-system-service%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"sdfz_url"],model.path] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        [tempArr addObject:imgUrl];
    }
    _cycleScrollView.imageURLStringsGroup = tempArr.copy;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = HEX_RGB(@"#FAFAFA");
        [self addSubview:self.topImageView];
        [self addSubview:self.cycleScrollView];
        [self addSubview:self.imageTitleView1];
        [self addSubview:self.imageTitleView2];
        [self addSubview:self.imageTitleView3];
        [self addSubview:self.imageTitleView4];
        [self setupConstraints];
    }
    return self;
}

- (void)setupConstraints{
    
    [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self);
        make.height.mas_equalTo(142.0f);
    }];
    
    [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(10.f);
        make.right.offset(-10.f);
        make.top.offset(kStatusBarHeight);
        make.height.mas_equalTo((kScreenWidth - 20) / (710 / 300));
    }];
    
    CGFloat w = (kScreenWidth - 18) / 4;
    CGFloat h = w;
    
    CGFloat margin = 9;//(kScreenWidth - 60 * 4) / 5;
    
//    CGFloat margin = (kScreenWidth - 60 * 4) / 5;
    
    [self.imageTitleView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(margin);
        make.top.equalTo(self.cycleScrollView.mas_bottom).offset(13.f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
    [self.imageTitleView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageTitleView1.mas_right);
        make.top.equalTo(self.imageTitleView1.mas_top).offset(0.f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
    [self.imageTitleView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageTitleView2.mas_right);
        make.top.equalTo(self.imageTitleView2.mas_top).offset(0.f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    
    [self.imageTitleView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageTitleView3.mas_right);
        make.top.equalTo(self.imageTitleView3.mas_top).offset(0.f);
        make.size.mas_equalTo(CGSizeMake(w, h));
    }];
    

    
//    self.backgroundColor = [UIColor clearColor];
    [self layoutIfNeeded];
    self.viewHeight = self.imageTitleView1.frame.origin.y + self.imageTitleView1.frame.size.height + 18;
}

- (UIImageView *)topImageView {
    if (!_topImageView) {
        _topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bjc"]];
    }
    return _topImageView;
}

- (SDCycleScrollView *)cycleScrollView {
    if (!_cycleScrollView) {
        _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@"banner"]];
        _cycleScrollView.showPageControl = YES;
        _cycleScrollView.autoScrollTimeInterval = 2.0f;
        _cycleScrollView.backgroundColor = [UIColor clearColor];
        _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleClassic;
        _cycleScrollView.currentPageDotColor = [UIColor colorWithHexString:kBgGreenColor alpha:1.0];
        _cycleScrollView.pageDotColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1.0];
        _cycleScrollView.layer.cornerRadius = 5.0f;
        _cycleScrollView.layer.masksToBounds = YES;
    }
    return _cycleScrollView;
}

-(BTRootImageTItleVIew *) imageTitleView1{
    if (!_imageTitleView1) {
        _imageTitleView1 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView1.title.text = @"通知";
        _imageTitleView1.imageView.image = [UIImage imageNamed:@"tz"];
        _imageTitleView1.delegate = self;
    }
    return _imageTitleView1;
}

-(BTRootImageTItleVIew *) imageTitleView2{
    if (!_imageTitleView2) {
        _imageTitleView2 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView2.title.text = @"考勤记录";
        _imageTitleView2.imageView.image = [UIImage imageNamed:@"zl"];
        _imageTitleView2.delegate = self;
    }
    return _imageTitleView2;
}



-(BTRootImageTItleVIew *) imageTitleView3{
    if (!_imageTitleView3) {
        _imageTitleView3 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView3.title.text = @"请假记录";
        _imageTitleView3.imageView.image = [UIImage imageNamed:@"zbju"];
        _imageTitleView3.delegate = self;
    }
    return _imageTitleView3;
}



-(BTRootImageTItleVIew *) imageTitleView4{
    if (!_imageTitleView4) {
        _imageTitleView4 = [[BTRootImageTItleVIew alloc] initWithFrame:CGRectZero];
        _imageTitleView4.title.text = @"选课报名";
        _imageTitleView4.imageView.image = [UIImage imageNamed:@"xtjl-1"];
        _imageTitleView4.delegate = self;
    }
    return _imageTitleView4;
}

#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    if ([self.delegate respondsToSelector:@selector(homeRootParentHeaderDidClickBanner:)]) {
        [self.delegate homeRootParentHeaderDidClickBanner:self.wheelBannerList[index]];
    }
}

/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index{
    
}


#pragma mark - BTRootImageTitleViewDelegate
-(void) rootImageViewDidTap:(BTRootImageTItleVIew *)imageTitleView
{
    if (imageTitleView == self.imageTitleView1) {
        if ([self.delegate respondsToSelector:@selector(homeRootParentHeaderDidClickNotice)]) {
            [self.delegate homeRootParentHeaderDidClickNotice];
        }
    }else if (imageTitleView == self.imageTitleView2) {
        if ([self.delegate respondsToSelector:@selector(homeRootParentHeaderDidClickAttendanceRecord)]) {
            [self.delegate homeRootParentHeaderDidClickAttendanceRecord];
        }
    }else if (imageTitleView == self.imageTitleView3) {
        if ([self.delegate respondsToSelector:@selector(homeRootParentHeaderDidClickLeaveRecord)]) {
            [self.delegate homeRootParentHeaderDidClickLeaveRecord];
        }
    }else if (imageTitleView == self.imageTitleView4) {
        if ([self.delegate respondsToSelector:@selector(homeRootParentHeaderDidClickCourseRegistration)]) {
            [self.delegate homeRootParentHeaderDidClickCourseRegistration];
        }
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
